package com.ssm.zhihu_ssm.controller;

import com.ssm.zhihu_ssm.entity.Comment;
import com.ssm.zhihu_ssm.entity.CommentReturn;
import com.ssm.zhihu_ssm.entity.User;
import com.ssm.zhihu_ssm.entity.UserMessage;
import com.ssm.zhihu_ssm.service.CommentService;
import com.ssm.zhihu_ssm.service.UserService;
import com.ssm.zhihu_ssm.util.ReturnMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class CommentController {

    @Autowired
    private CommentService commentService;
    @Autowired
    private UserService userService;


    @RequestMapping("/getComment")//得到回答的所有评论
    @ResponseBody
    private Map<String, Object> getcomment(int id ,int state) {
        System.out.println(id);
        List<CommentReturn> comments = commentService.getComment( id,state);
        System.out.println(comments);
        Map<String, Object> map = ReturnMap.ReturnMapS(comments);
        return map;

    }

    @RequestMapping("/addgoodNum")//得到回答的所有评论
    @ResponseBody
    private Map<String, Object> addgoodNum(int id ) {
        boolean comments = commentService.addgoodNum( id);
        System.out.println(comments);
        Map<String, Object> map = ReturnMap.ReturnMapS(comments);
        return map;

    }

    @RequestMapping("/insertComment")//发送评论
    @ResponseBody
    private Map<String, Object> insertComment(int aid,String phone,int fromid ,String content,int state) {
        int id = userService.findId(phone);
        boolean comments = commentService.insertComment(aid,id,fromid,content,state);
        System.out.println(comments);
        Map<String, Object> map = ReturnMap.ReturnMapS(comments);
        return map;

    }



}
